/*
 * dwt_utils.h
 *
 *  Created on: Apr 21, 2009
 *      Author: alex
 */

#ifndef DWT_UTILS_H_
#define DWT_UTILS_H_

#include "dwt_types.h"
#include <stdio.h>


/**
 * Sets the search path for filters - the search path is
 * used by dwt_filter_load
 */
void dwt_filter_set_path(char* path);

/**
 * Loads a filter from the file <filtername>.csv located in
 * the filter path. The filter path is set by calling
 * dwt_set_filter_path(char* path). In case the filter path
 * is null, the file is searched in the current directory.
 */
dwt_filter_t* dwt_filter_load(char* filtername);

/**
 * Reads filter coefficients from provided file f and
 * returns a dwt_filter_t object. The format of the matrix in
 * file f should be as follows:
 *  - the number of columns gives the filter length
 *  - the number of rows gives 2*number of bands
 *  - first half of the lines are analysis coefficients
 *  - last half of the lines are reconstruction coefficients
 */
dwt_filter_t* dwt_filter_read(FILE* f);

/**
 * Allocates memory for the DWT filter object and sets its fields
 * except from the given arguments
 */
dwt_filter_t* dwt_filter_alloc(int nbands, int length, char* name);

/**
 * Writes information about the provided filter to file f in a nice format
 */
void dwt_filter_write(FILE* f, dwt_filter_t* filter);

/**
 * Frees the memory occupied by the filter object
 */
void dwt_filter_free(dwt_filter_t* filter);

/**
 * Allocates memory for the DWT parameters object
 */
dwt_params_t* dwt_params_alloc(int ndims);

/**
 * Writes information about the provided parameters object to file f in a nice format
 */
void dwt_params_write(FILE* f, dwt_params_t* params);

/**
 * Frees the memory occupied by the params object
 * (including all the objects it points)
 */
void dwt_params_free(dwt_params_t* params);

/**
 * Returns the CDJV edge filters and the pre/post
 * conditioning filters for the specified degree Daubechies wavelet
 */
dwt_cdjv_t* dwt_cdjv_load(char* filtername);

/**
 * Frees the CDJV structure pointed by cdjv
 */
void dwt_cdjv_free(dwt_cdjv_t* cdjv);

/**
 * Writes the CDJV structure pointed by cdjv to stream f
 */
void dwt_cdjv_write(FILE* f, dwt_cdjv_t* cdjv);

#endif /* DWT_UTILS_H_ */
